/**
 * Created by user on 2017/12/17.
 */
let dbInstances={};
let dbFunctions={};
let dbObjects={};
let dbCodes={};
let dbEvents={};
let dbEventsType={};

export default {
    Instances:{
        put(pck){
            let {id, father, instanceJSON}=pck;
            dbInstances[id]=pck;
        },
        get(id){
            return dbInstances[id];
        }
    },
    Functions:{
        put(args){
            let {id}=args;
            dbFunctions[id]=args;
        },
        get(id){
            return dbFunctions[id];
        }

    },
    Objects:{
        put(args){
            let {id, json} =args;
            dbObjects[id]=json;
        },
        get(id){
            return dbObjects[id];
        }
    },
    Codes:{
        put(args){
            let {name,code}=args;
            dbCodes[name]=code;
        },
        get(name){
            return dbCodes[name];
        }
    },
    Events:{
        put(eventObj){
            dbEvents[eventObj.name]=eventObj;
            if (typeof dbEventsType[eventObj.type] === "undefined")
                dbEventsType[eventObj.type]=[eventObj];
            else
                dbEventsType[eventObj.type].push(eventObj);
        },
        get(eventName){
            return dbEvents[eventName];
        },
        find(eventType){

        }
    },
    dump(){
        console.log('instances',dbInstances);
        console.log('functions',dbFunctions);
        console.log('codes',dbCodes);
        console.log('objects',dbObjects);
        console.log('events', dbEvents);
    }
}